import fs from "fs";
import path from "path";
import uuid from "node-uuid";

import {
    management,
    pc_userinfo,
    pc_bookinfo,
    pc_pass,
    pc_hot,
    pc_addHot,
    pc_delHot
} from "./mySqlHandler";
import { response } from "express";

/*---pc 后端---*/
export const serverPC = (app) => {

    // 管理员登录
    app.post('/admininfo', (request, response) => {
        const { username, password } = request.body
        management(username, res => {
            response.send({ code: '01', msg: "ok", data: res.data })
        })
    });

    // 用户列表
    app.post('/pc_userinfo', (request, response) => {
        // const { nickname, phonenum, email, age, head_url, signature } = request.body
        pc_userinfo(res => {
            response.send({ code: ' 01', msg: "ok", data: res.data })
        })
    })

    // 用户列表
    app.post('/pc_bookinfo', (request, response) => {
        // const { nickname, phonenum, email, age, head_url, signature } = request.body
        pc_bookinfo(res => {
            response.send({ code: ' 01', msg: "ok", data: res.data })
        })
    });
    // 修改 图书状态
    app.post('/pc_pass',(request, response)=>{
        const {bid,value} = request.body
        pc_pass(bid,value,res =>{
            response.send({ code: ' 01', msg: "ok", data: res.data })
        })
    });

    // 活动列表
    app.post('/pc_hot', (request, response) => {
        pc_hot(res => {
            response.send({ code: ' 01', msg: "ok", data: res.data })
        })
    });
    // 添加活动
    app.post('/pc_addHot',(request, response)=>{
        const {Sid,shopName,shopNum,shopType,collage,startTime,endTime,stuAuth,price} = request.body
        pc_addHot(Sid,shopName,shopNum,shopType,collage,startTime,endTime,stuAuth,price,res =>{
            response.send({ code: ' 01', msg: "ok", data: res.data })
            
        })
    });

    // 修改活动状态
    app.post('/pc_changeHot',(request, response)=>{
        const {Sid,value} = request.body
        pc_changeHot(Sid,value,res=>{
            if(Sid){
               let fil= res.data.filter((val)=>{
                    if(val.Sid == Sid) return val
                })
                response.send({ code: ' 01', msg: "ok", data: fil })
            }
            
        })
    });
    
    // 删除活动状态
    app.post("/pc_delet",(request,response) =>{
        const {Sid} =request.body
        pc_delHot(Sid,res=>{
            response.send({ code: ' 01', msg: "ok", data: res.data })
        })
    })     

};